/*
 *@Author: 张楚
 *@Date: 2021-10-22 16:52:47
 *@Description: 听课记录
*/

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class ListenClassRecordpage extends StatefulWidget {
  const ListenClassRecordpage({Key key}) : super(key: key);
  @override
  _ListenClassRecordpageState createState() => _ListenClassRecordpageState();
}

class _ListenClassRecordpageState extends State<ListenClassRecordpage> {
  GlobalKey textKey = GlobalKey();
  void showoverlay() {
    RenderBox renderBox = textKey.currentContext.findRenderObject();
    var offset = renderBox.localToGlobal(Offset(0.0, renderBox.size.height));
    OverlayEntry overlayEntry = OverlayEntry(builder: (_) {
      return Positioned(
          left: 0,
          right: 0,
          top: offset.dy, //按钮位置
          child: Container(
            //
            height: 50,
            color: Colors.white,
            child: GestureDetector(
              onTap: () {
                print("#####");
              },
              child: Text(
                "翡翠城",
                style: TextStyle(color: Colors.white, fontSize: 16),
              ),
            ),
          ));
    });

    Overlay.of(context).insert(overlayEntry);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('听课记录'),
        ),
        body: SingleChildScrollView(
            child: Column(children: [
          GestureDetector(
            behavior: HitTestBehavior.opaque,
            onTap: () {
              showoverlay();
            },
            child: Center(
              child: Container(
                color: Colors.greenAccent,
                key: textKey, //绑定的key
                padding: EdgeInsets.all(15),
                child: Text("弹框"),
              ),
            ),
          )
        ])));
  }
}
